<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\logic;



use app\common\model\EthAccount;
use app\common\model\EthAccountLog;
use app\common\model\Member;
use app\common\model\OtcOrder;
use app\common\model\OtcShop;
use app\common\model\UserAccount;
use app\common\model\UserAccountLog;
use app\common\model\Wallet;
use think\Db;

/**
 * 工单接口逻辑
 */
class Work extends ApiBase
{


    /***
     * 工单列表
     */

    public function work_order_list(){
        $member=$this->logicApiBase->member;
        $uid=$member['id'];
        $where['user_id']=$uid;
        $list=$this->modelChannelWorkContent->getList($where,'id,class,state,title,content,create_time,cover_id','id desc');

        foreach ($list as $k=>$v){
            $list[$k]['reply']=$v->reply;
            $list[$k]['class_name']=$v->cate->classname;
            $list[$k]['image']=$v->image;
            unset($v->cate);

            unset($v->class);
        }
        return $list;
    }





    /***
     * 工单详情
     */

    public function work_order_detail($data){
        $info=$this->modelChannelWorkContent->getInfo(['id'=>$data['id']],'id,class,state,title,content,create_time,cover_id');
        $info['image']=$info->image;
        $info['class_name']=$info->cate->classname;
        unset($info->cate);

        unset($info->class);
        $this->modelChannelWorkComment->where(['wid'=>$data['id']])->update(['is_read'=>1]);
        $info['reply']=$info->reply;

        return $info;
    }









    /***
     *提交工单
     */

    public function  work_order_add($data){
        $member=$this->logicApiBase->member;
        $uid=$member['id'];


        $validate_result = $this->validateWork->scene('edit')->check($data);
        if (!$validate_result) {
            return ajaxreturn(1,lang( $this->validateWork->getError()));
        }
        $data['user_id']=$uid;
       // dd($data);
        $this->modelChannelWorkContent->setInfo($data);
        return  ajaxreturn(0,lang('提交工单成功'));


    }


    /***
     *提交回复
     */

    public function  work_comment_order_add($data){
        $member=$this->logicApiBase->member;
        $uid=$member['id'];

        $info=$this->modelChannelWorkContent->getInfo(['id'=>$data['id'],'user_id'=>$member['id']]);
        if(!$info){
            return  ajaxreturn(1,lang('工单不存在'));
        }
        if($info['state']==4 || $info['state']==5){
            return  ajaxreturn(1,lang('工单已结束'));
        }

        $validate_result = $this->validateWork->scene('comment')->check($data);
        if (!$validate_result) {
            return ajaxreturn(1,lang( $this->validateWork->getError()));
        }
        $data['user_id']=$uid;
        $data['wid']=$data['id'];
        unset($data['id']);
        // dd($data);
        $this->modelChannelWorkComment->setInfo($data);
        return  ajaxreturn(0,lang('回复成功'));


    }














}
